package com.atguigu.tingshu.dispatch.job;

import com.atguigu.tingshu.search.client.SearchFeignClient;
import com.atguigu.tingshu.user.client.UserFeignClient;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DispatchHandler {

    /**
     * 动态从web管理页将任务参数传入
     */



    @XxlJob("hellojob")
    public void firstJobHandler() {
        log.info("xxl-job项目集成测试");
    }


    @XxlJob("hellojob111")
    public void hellojob() {
        //1.获取任务参数 业务限制入参是JSON格式
        String jobParamJson = XxlJobHelper.getJobParam();
        Long topN = Long.valueOf(jobParamJson);

        // 可参考Sample示例执行器中的示例任务"ShardingJobHandler"了解试用
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        log.info("shardIndex:{},shardTotal:{}",shardIndex,shardTotal);
        System.out.println("测试dispa使用xxljob是否成功...");
    }


    @Autowired
    private SearchFeignClient searchFeignClient;

    /**
     * 任务逻辑：远程调用搜索服务更新排行榜数据
     */
    @XxlJob("updateAlbumRanking")
    public void updateAlbumRanking() {
        log.info("[定时任务]远程调用搜索服务更新排行榜数据");
        searchFeignClient.updateLatelyAlbumRanking();
    }



    @Autowired
    private UserFeignClient userFeignClient;

    /**
     * 任务逻辑：远程调用用户服务更新VIP标识
     */
    @XxlJob("updateVipExpireStatus")
    public void updateVipExpireStatus() {
        log.info("[定时任务]远程调用用户服务更新VIP标识");
        userFeignClient.updateVipExpireStatus();
    }
}